package me.zhanshi123.vipsystem.feature.vipjoin;

import cn.nukkit.Player;
import cn.nukkit.utils.ConfigSection;

import java.util.HashMap;
import java.util.Map;

public class VipJoinGroup {
    private ConfigSection configSection;

    private Map<String, VipJoinAction> data = new HashMap<>();

    public VipJoinGroup(ConfigSection configSection) {
        this.configSection = configSection;
        configSection.getKeys(false).forEach(key -> data.put(key, new VipJoinAction(configSection.getList(key + ".join"), configSection.getList(key + ".leave"))));
    }

    public Map<String, VipJoinAction> getData() {
        return data;
    }

    public VipJoinAction getGroup(Player player) {
        for (Map.Entry<String, VipJoinAction> entry : data.entrySet()) {
            if (player.hasPermission("vipjoin." + entry.getKey())) {
                return entry.getValue();
            }
        }
        return null;
    }
}
